package com.bbs.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.sun.org.apache.bcel.internal.generic.NEW;

public class DateUtil {
	
	/**
	 * 调整日期格式
	 */
	public String getNowTime(String pattern){
		DateFormat df = new SimpleDateFormat(pattern);
		return df.format(new Date());
	}
	/**
	 * 两个日期间隔了多少秒
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public long timeLagForSecond(String startTime ,String endTime){
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long days = 0;
		try
		{
		    Date d1 = df.parse(endTime);
		    Date d2 = df.parse(startTime);
		    long diff = d1.getTime() - d2.getTime();
		    days = diff/1000;
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		return days;
	}
	/**
	 * 两个日期间隔了多少天
	 * @param start
	 * @param end
	 * @return
	 */
	public long toDay(String start, String end){
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		long days = 0;
		try
		{
		    Date d1 = df.parse(start);
		    Date d2 = df.parse(end);
		    long diff = d2.getTime() - d1.getTime();
		    days = diff/(1000 * 60 * 60 * 24);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return days;
	}
	public static void main(String[] args) {
		System.out.println(new Date());
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(df.format(new Date()));
	}
}
